package concurrent;

/**
 * @auther hanchao
 * @date 2017/3/25 15:11
 */
public class WaitTest {
    public static void main(String[] args) throws InterruptedException {
        final WaitTest w = new WaitTest();
        for (int i = 0; i < 2; i++) {
            new Thread(){
                @Override
                public void run() {
                    w.testWait();
                }
            }.start();
        }
        Thread.sleep(1000);
        new Thread(){
            @Override
            public void run() {
                w.testNotify();
            }
        }.start();
    }

    public synchronized void testWait(){
        System.out.println("go go go");
        try {
            this.wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("over");
    }

    public synchronized void testNotify(){
        System.out.println("nnnnn");
        try {
            System.out.println("---");
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.notifyAll();
    }
}
